package com.dozen.commonbase.view.autopull;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.dozen.commonbase.R;
import com.dozen.commonbase.bean.DozenBean;

import java.util.List;

/**
 * @author: Dozen
 * @description:
 * @time: 2021/3/29
 */
public class AutoTextAdapter extends RecyclerView.Adapter<AutoTextAdapter.BaseViewHolder> {
    private final List<DozenBean> mData;

    public AutoTextAdapter(List<DozenBean> list) {
        this.mData = list;
    }

    @Override
    public BaseViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.view_auto_pull_text, parent, false);
        BaseViewHolder holder = new BaseViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(BaseViewHolder holder, int position) {
        DozenBean data = mData.get(position % mData.size());

        holder.tv.setText(data.getName());
    }

    @Override
    public int getItemCount() {
        return Integer.MAX_VALUE;
    }

    class BaseViewHolder extends RecyclerView.ViewHolder {
        TextView tv;

        public BaseViewHolder(View itemView) {
            super(itemView);
            tv = itemView.findViewById(R.id.auto_pull_text);
        }
    }
}